package com.skt.common_hr.common.approval
{
	import com.skt.common_hr.common.Variables;
	import com.skt.common_hr.common.puremvc.CommonProxy;
	
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;

	public class ApprovalProxy extends CommonProxy
	{
		public static const NAME:String = "ApprovalProxy";
		
		public static const SAVE_APPROVAL_COMPLETE:String 	= "saveApprovalComplete";
		public static const SAVE_APPROVAL_FAILED:String 	= "saveApprovalFailed";
		
		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function ApprovalProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		
		/**
		 * data load를 수행
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 * 
		 * @param pernr 사번
		 * @return void
		 */
		public function requestApproval(type:String, key:String, title:String, content:String, xmlData:String, appLine:Array, files:Array=null, isHaveEacc:String=''):void
		{			
			var params:Object = new Object();
			params["I_PROCGBN"] = type;
			params["I_REQNR"] 	= key;
			params["I_TITLE"] 	= title;
			params["I_HTML"] 	= content;
			params["I_XML"] 	= xmlData;
			
			if(Variables.company == 'SAC') {
				params["I_EVID"] 	= isHaveEacc;	
			}
			  
			
			var tables:Object = new Object();
			tables["INPUT1"]	= files;
			tables["INPUT2"]	= appLine;
			saveData("Z_HR_0100", params, tables, resultSave, faultSave);
		}
		
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 신청현황 리스트 조회 성공
		 */
		public function resultSave(event:ResultEvent):void
		{
			if(retCode==0) {  
				facade.sendNotification(SAVE_APPROVAL_COMPLETE, this);
			}
			else {
				trace("결재 요청 실패 : " + retCode + ", " + retText);
				var a:Alert = Alert.show("결재 요청 실패 : " + retCode + ", " + retText);
				a.validateNow ();
				a.move (a.x, 100);
								
				facade.sendNotification(SAVE_APPROVAL_FAILED, this);
			}
		}
		
		/**
		 * 신청현황 리스트 조회 실패
		 */
		private function faultSave(event:FaultEvent):void
		{
			facade.sendNotification(SAVE_APPROVAL_FAILED, this);
		}
	}
}